{% extends 'myadmin/index.html' %}

{% block title %}
<title>商品添加</title>
{% endblock %}


{% block con %}
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-fl">
                        商品分类添加
                    </div>
                    <div class="widget-function am-fr">
                        <a href="javascript:;" class="am-icon-cog">
                        </a>
                    </div>
                </div>
                <div class="widget-body am-fr">
                    <form action="{% url 'myadmin_goods_insert' %}" method="POST" enctype="multipart/form-data"
                          class="am-form tpl-form-line-form">
                        {% csrf_token %}

                        <div class="am-form-group">
                            <label for="user-name" class="am-u-sm-3 am-form-label">
                                所属分类
                            </label>
                            <select name="cateid" data-am-selected="{btnSize: 'sm'}" style="display: none;">
                                <option value="0">所属顶级分类</option>
                                {% for v in catelist %}
                                <option value="{{ v.id }}" {% if v.pid == 0 %} disabled {% endif %}>{{ v.sub }}{{ v.name
                                    }}
                                </option>
                                {% endfor %}
                            </select>

                        </div>


                        <div class="am-form-group">
                            <label for="user-name" class="am-u-sm-3 am-form-label">
                                商品名称
                            </label>
                            <div class="am-u-sm-9">
                                <input type="text" name="goodsname" class="tpl-form-input"
                                       placeholder="商品名称">
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label for="user-name" class="am-u-sm-3 am-form-label">
                                商品标题
                            </label>
                            <div class="am-u-sm-9">
                                <input type="text" name="title" class="tpl-form-input"
                                       placeholder="商品标题">
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label for="user-name" class="am-u-sm-3 am-form-label">
                                商品价格
                            </label>
                            <div class="am-u-sm-9">
                                <input type="text" name="price" class="tpl-form-input"
                                       placeholder="商品价格">
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label for="user-name" class="am-u-sm-3 am-form-label">
                                商品库存
                            </label>
                            <div class="am-u-sm-9">
                                <input type="text" name="goodsnum" class="tpl-form-input"
                                       placeholder="商品库存">
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label for="user-weibo" class="am-u-sm-3 am-form-label">
                                封面图
                            </label>
                            <div class="am-u-sm-9">
                                <div class="am-form-group am-form-file">
                                    <div class="tpl-form-file-img">
                                        <img id="showImg" style="width: 200px;" alt="">
                                    </div>
                                    <button type="button" class="am-btn am-btn-danger am-btn-sm">
                                        <i class="am-icon-cloud-upload"></i> 添加封面图片
                                    </button>
                                    <input id="ReadFile" name="pic" type="file" multiple="">
                                </div>
                            </div>
                        </div>
                        <script type="text/javascript">
                            $('#ReadFile').change(function () {
                                var file = this.files[0];

                                //限定上传文件的类型，判断是否是图片类型
                                if (!/image\/\w+/.test(file.type)) {
                                    alert("只能选择图片");
                                    return false;
                                }
                                var reader = new FileReader();
                                reader.readAsDataURL(file);
                                reader.onload = function (e) {
                                    base64Code = this.result;
                                    //把得到的base64赋值到img标签显示
                                    $("#showImg").attr("src", base64Code);
                                }
                            })
                        </script>
                        <div class="am-form-group">
                            <label for="user-name" class="am-u-sm-3 am-form-label">
                                商品简介
                            </label>
                            <link rel="stylesheet" type="text/css"
                                  href="/ueditor/UE/third-party/SyntaxHighlighter/shCoreDefault.css">
                            <script type="text/javascript"
                                    src="/ueditor/UE/third-party/SyntaxHighlighter/shCore.js"></script>
                            <script type="text/javascript" src="/ueditor/UE/ueditor.config.js"></script>
                            <script type="text/javascript" src="/ueditor/UE/ueditor.all.min.js"></script>
                            <script type="text/javascript" src="/ueditor/UE/lang/zh-cn/zh-cn.js"></script>


                            <div class="am-form-group">
                                <label for="user-intro" class="am-u-sm-3 am-form-label"></label>
                                <div class="am-u-sm-9">
                                    <!-- <textarea name="descr" class="" rows="10" id="user-intro" placeholder="请输入商品简介"></textarea> -->
                                    <!-- <script id="editor" type="text/plain" style="width:100%;height:500px;"></script> -->
                                    <script id="editor" name="content" type="text/plain"
                                            style="height:500px; color:black"></script>
                                </div>
                            </div>


                            <script type="text/javascript">
                                var ue = UE.getEditor('editor');
                                SyntaxHighlighter.all();
                            </script>
                            <!--<div class="am-u-sm-9">-->
                            <!--<input type="text" name="goodinfo" class="tpl-form-input"-->
                            <!--placeholder="商品详情">-->
                            <!--</div>-->
                        </div>

                        <div class="am-form-group">
                            <div class="am-u-sm-9 am-u-sm-push-3">
                                <button class="am-btn am-btn-primary tpl-btn-bg-color-success ">
                                    提交
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}